package com.app;


import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.text.TextUtils;
import android.widget.Toast;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.Volley;
import com.app.net.NetHelper;
import com.app.umeng.Umeng;
import com.app.util.Utils_Log;


public abstract class BaseRawActivity extends  FragmentActivity {
	Toast mToast;
	protected RequestQueue requestQueue;
	
	Bundle mBundle;
	
	private String TAG = BaseActivity.class.getSimpleName();
	
	@Override
	protected void onCreate(Bundle arg0) {
		super.onCreate(arg0);
		
		
		mBundle = arg0;
		Utils_Log.d("activity_life", getClass().getName() + "----->create");
		
		
		Umeng.OnCreate_analytics(this);
		Umeng.OnCreate_message(this);
		
		
		this.requestQueue = Volley.newRequestQueue(this);
	
		AppManager.getAppManager().addActivity(this);

	 
		setContentView(InitLayout());
	}


	/**
	 * 根据输入文字提示信息
	 * 
	 * @param text
	 *            提示信息
	 */
	public void ShowToast(final String text) {
		if (!TextUtils.isEmpty(text)) {
			runOnUiThread(new Runnable() {

				@Override
				public void run() {

					if (mToast == null) {
						mToast = Toast.makeText(getApplicationContext(), text,
								Toast.LENGTH_SHORT);
					} else {
						mToast.setText(text);
					}
					mToast.show();
				}
			});

		}
	}

	/**
	 * 根据ID提示信息
	 * 
	 * @param resId
	 *            资源ID
	 */
	public void ShowToast(final int resId) {
		runOnUiThread(new Runnable() {

			@Override
			public void run() {
				if (mToast == null) {
					mToast = Toast.makeText(
							BaseRawActivity.this.getApplicationContext(), resId,
							Toast.LENGTH_SHORT);
				} else {
					mToast.setText(resId);
				}
				mToast.show();
			}
		});

	}

	
	
	private long lastClickTime;

	/**
	 * 判断事件出发时间间隔是否超过预定值
	 * 
	 * @Description
	 * @return
	 * @Author lewis(lgs@yitong.com.cn) 2014-4-29 上午9:12:20
	 */
	public boolean isFastDoubleClick() {
		long time = System.currentTimeMillis();
		long timeD = time - lastClickTime;
		if (0 < timeD && timeD < 1000) {
			return true;
		}
		lastClickTime = time;
		return false;
	}

	
	
	
	
	///////////////////////////////////////////////////////////////////////////////////////
	
	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
		Utils_Log.d("activity_life", getClass().getName() + "----->start");
	}

	@Override
	protected void onRestart() {
		// TODO Auto-generated method stub
		super.onRestart();
		Utils_Log.d("activity_life", getClass().getName() + "----->restart");
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		Utils_Log.d("activity_life", getClass().getName() + "----->resume");
		
		Umeng.OnResume_analytics(this);
	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		Utils_Log.d("activity_life", getClass().getName() + "----->pause");
		
		Umeng.OnPause_analytics(this);
	}

	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
		super.onStop();
		Utils_Log.d("activity_life", getClass().getName() + "----->stop");
	}

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();

		Umeng.onDestroy(this);
		
		if (this.requestQueue != null){
			this.requestQueue.cancelAll( NetHelper.TAG_URL );
		}
		
		AppManager.getAppManager().finishActivity(this);
		Utils_Log.d("activity_life", getClass().getName() + "----->destroy");
	}
	
	
	public abstract int InitLayout();
	
	
}



